const express = require("express");
const pool = require("../pool.js");
const select = express.Router();

// 测试接口：http://localhost:3333/select?food=甜甜圈
select.get("/", (req, res, next) => {
  let food = "%" + req.query.food + "%";
  console.log(food);
  const sql = "SELECT * FROM hbb_list WHERE food LIKE ? OR material LIKE ?;";
  pool.query(sql, [food, food], (err, result) => {
    if (err) {
      next(err);
      return;
    }
    res.send({ code: 200, msg: "查询成功", data: result });
    console.log(result);
  });
});

// 暴露搜索模块
module.exports = select;
